home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: writeLocalDisk.c,v $
- * $Revision: 1.2 $
- * $Date: 1996/05/04 23:51:48 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
- #include "sysdefs.h"
- #include <sys/file.h>
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "disk.h"
- #include "queues.h"
- #include "diskproc_globals.h"
- #include "diskproc_intfuncs.h"
- #include "diskproc_extfuncs.h"
-
-
- extern char *ShmAddress;
- extern int Fd;
-
- #ifdef DISKPROC_MAKE
- /* see comments below where Shmstruct is used. */
- extern struct shmid_ds Shmstruct;
- #endif DISKPROC_MAKE
-
-
-
- #ifdef DISKPROC_MAKE
- static void
- generateVector(
- DISKMSG *message,
- struct iovec ioPageVec[],
- int& vecSize
- )
- {
- int amountInBuf = 0;
- int diskVecUsed = 0;
- int i;
-
- if (!RawDev || message->body.diskVecCount == 1) {
- for (i = 0; i < message->body.diskVecCount; i++) {
- ioPageVec[i].iov_base = ShmAddress+(int)message->body.diskVec[i].bufIndex;
- ioPageVec[i].iov_len = (int)message->body.diskVec[i].length;
- }
-
- // return the size of the vector
- vecSize = message->body.diskVecCount;
- return;
- }
-
- SM_ASSERT(LEVEL_3, BlockBuf != NULL);
-
- i = 0;
- ioPageVec[0].iov_base = BlockBuf;
- while(i < message->body.diskVecCount) {
-
- /* Include this check only for the disk process because
- * Shmstruct doesn't exist in the server process. The check
- * is unnecessary in the single process case anyway.
- */
- # if defined(mips) || defined (vax)
- SM_ASSERT(LEVEL_3, ((message->body.diskVec[i].bufIndex < Shmstruct.sm_size) && (message->body.diskVec[i].bufIndex >= 0)) );
- # elif defined(sparc) || defined(_AIX) || defined(hpux) || defined(linux)
- SM_ASSERT(LEVEL_3, ((message->body.diskVec[i].bufIndex < Shmstruct.shm_segsz) && (message->body.diskVec[i].bufIndex >= 0)) );
- # elif !(defined(mips) || defined (vax) || defined(sparc) || defined(_AIX) || defined(hpux) || defined(linux))
- unsupported
- # else
- /* can't put the else part here because ultrix cpp is broken */
- # endif
-
- if ( (amountInBuf + message->body.diskVec[i].length) > BlockBufSize) {
- break; /* block buffer is full */
- }
-
- memcpy(BlockBuf+amountInBuf, ShmAddress+(int)message->body.diskVec[i].bufIndex, message->body.diskVec[i].length);
-
- amountInBuf += message->body.diskVec[i].length;
- i++;
- }
- diskVecUsed = i;
- SM_ASSERT(LEVEL_3, diskVecUsed>0);
- SM_ASSERT(LEVEL_3, (amountInBuf <= BlockBufSize) );
- ioPageVec[0].iov_len = amountInBuf;
-
- for (i = diskVecUsed; i < message->body.diskVecCount; i++) {
- ioPageVec[i-diskVecUsed+1].iov_base = ShmAddress+(int)message->body.diskVec[i].bufIndex;
- ioPageVec[i-diskVecUsed+1].iov_len = (int)message->body.diskVec[i].length;
- }
- // return the size of the vector
- vecSize = 1 + message->body.diskVecCount-diskVecUsed;
-
- } /* generateVector */
-
-
- #else /* DISKPROC_MAKE */
-
- static void
- generateVector(
- DISKMSG *message,
- struct iovec ioPageVec[],
- int& vecSize
- )
- {
- int i;
-
- for (i = 0; i < message->body.diskVecCount; i++) {
- ioPageVec[i].iov_base = ShmAddress+(int)message->body.diskVec[i].bufIndex;
- ioPageVec[i].iov_len = (int)message->body.diskVec[i].length;
- }
-
- // return the size of the vector
- vecSize = message->body.diskVecCount;
-
- } /* generateVector */
-
- #endif /* DISKPROC_MAKE */
-
-
- void
- writeLocalDisk (
- DISKMSG *message
- )
- {
- int length;
- int writeLength;
- struct iovec ioPageVec[MAX_DISK_IOVEC];
- int vecSize;
- int i;
-
-
- TRPRINT(TR_DISKRW, TR_LEVEL_1, ("writing at:%d numVectors:%d",
- message->body.offset, message->body.diskVecCount));
-
- /*
- * attempt to seek to the place in the file
- */
- if (lseek(Fd, (int)(message->body.offset), L_SET) < 0) {
-
- /*
- * print an error message
- */
- SM_ERROR(TYPE_SYS, errno);
-
- /*
- * reply in the negative
- */
- if (errno == 0) SM_ERROR(TYPE_FATAL, esmINTERNAL);
- message->header.params.out.errno = errno;
- message->diskmagic = DISK_MESSAGE_MAGIC;
- replyDiskMessage(message);
- }
-
- /*
- * Write each page separately. See code in "ifdef JUNK" for
- * how to use a vectored write.
- * If this is the disk process we first call collectVector
- * which copies the pages to a contiguous location in memory
- * and adjusts the vector.
- */
- SM_ASSERT(LEVEL_3, (message->body.diskVecCount > 0) &&
- (message->body.diskVecCount <= MAX_DISK_IOVEC));
- generateVector(message, ioPageVec, vecSize/*OUT*/);
-
- for (i = 0; i < vecSize; i++) {
-
- /* attempt to write the disk */
- if ((writeLength = write(Fd, ioPageVec[i].iov_base, ioPageVec[i].iov_len)) < ioPageVec[i].iov_len) {
-
- /* print an error message */
- SM_ERROR(TYPE_SYS, errno);
-
- /* reply in the negative */
- if (errno == 0) SM_ERROR(TYPE_FATAL, esmINTERNAL);
- message->header.params.out.errno = (FOUR)errno;
- message->diskmagic = DISK_MESSAGE_MAGIC;
- replyDiskMessage(message);
- }
- }
-
- TRPRINT(TR_DISKRW, TR_LEVEL_2, ("write successful"));
-
- /*
- * reply in the positive
- */
- message->header.params.out.errno = esmNOERROR;
- message->diskmagic = DISK_MESSAGE_MAGIC;
- replyDiskMessage(message);
-
- }
-
- /*
- * The following code does not work at this time because
- * writev does not work to a raw device.
- */
- #ifdef JUNK
-
- /*
- * Generate the io vector for the write
- */
- SM_ASSERT(LEVEL_3, (message->body.diskVecCount > 0) &&
- (message->body.diskVecCount <= MAX_DISK_IOVEC));
- length = 0;
- for (i = 0; i < message->body.diskVecCount; i++) {
-
- #ifdef DISKPROC_MAKE
- /* Include this check only for the disk process because
- * Shmstruct doesn't exist in the server process. The check
- * is unnecessary in the single process case anyway.
- */
- # if defined(mips) || defined (vax)
- SM_ASSERT(LEVEL_3, ((message->body.diskVec[i].bufIndex < Shmstruct.sm_size) && (message->body.diskVec[i].bufIndex >= 0)) );
- # elif defined(sparc)
- SM_ASSERT(LEVEL_3, ((message->body.diskVec[i].bufIndex < Shmstruct.shm_segsz) && (message->body.diskVec[i].bufIndex >= 0)) );
- # elif !(defined(mips) || defined (vax) || defined(sparc))
- unsupported
- # else
- /* can't put the else part here because ultrix cpp is broken */
- # endif
- #endif DISKPROC_MAKE
-
- ioPageVec[i].iov_base = ShmAddress+(int)message->body.diskVec[i].bufIndex;
- ioPageVec[i].iov_len = message->body.diskVec[i].length;
-
- /* pull the length out of the message */
- length += message->body.diskVec[i].length;
- }
-
- /*
- * attempt to write the disk
- */
- if ((writeLength = writev(Fd, ioPageVec, message->body.diskVecCount)) < length) {
-
- /*
- * print an error message
- */
- SM_ERROR(TYPE_SYS, errno);
-
- /*
- * reply in the negative
- */
- if (errno == 0) SM_ERROR(TYPE_FATAL, esmINTERNAL);
- message->header.params.out.errno = errno;
- message->diskmagic = DISK_MESSAGE_MAGIC;
- replyDiskMessage(message);
-
- } else {
-
- TRPRINT(TR_DISKRW, TR_LEVEL_2, ("write successful"));
-
- /*
- * reply in the positive
- */
- if (errno == 0) SM_ERROR(TYPE_FATAL, esmINTERNAL);
- message->header.params.out.errno = esmNOERROR;
- message->diskmagic = DISK_MESSAGE_MAGIC;
- replyDiskMessage(message);
- }
- #endif /* JUNK */
-